package org.example.managementsystem.service;

import org.example.managementsystem.model.Product_Plan_Detail;
import org.example.managementsystem.repository.Product_Plan_DetailDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class Product_Plan_DetailService {
    private final Product_Plan_DetailDao productPlanDetailDao;
    @Autowired
    public Product_Plan_DetailService(Product_Plan_DetailDao productPlanDetailDao) {
        this.productPlanDetailDao = productPlanDetailDao;
    }

    public Product_Plan_Detail addProduct_Plan_Detail(Product_Plan_Detail productPlanDetail) {
        Long id = productPlanDetailDao.insertProduct_Plan_Detail(productPlanDetail);
        productPlanDetail.setDetail_id(id);
        return productPlanDetail;
    }

    public boolean updateProduct_Plan_Detail(Product_Plan_Detail productPlanDetail) {
        return productPlanDetailDao.updateProduct_Plan_Detail(productPlanDetail) > 0;
    }

    public boolean deleteProduct_Plan_Detail(Long detailId) {
        return productPlanDetailDao.deleteProduct_Plan_Detail(detailId) > 0;
    }

    public Product_Plan_Detail getProduct_Plan_DetailById(Long detailId) {
        return productPlanDetailDao.getProduct_Plan_DetailById(detailId);
    }

    public List<Product_Plan_Detail> getAllProduct_Plan_Details() {
        return productPlanDetailDao.getAllProduct_Plan_Details();
    }
    // Product_Plan_DetailService.java
    public List<Product_Plan_Detail> getDetailsByPlanId(Long planId) {
        return productPlanDetailDao.getProduct_Plan_DetailsByPlanId(planId);
    }
    // Product_Plan_DetailService.java
    public boolean updateProduct_Plan_DetailById(Product_Plan_Detail detail) {
        return productPlanDetailDao.updateProduct_Plan_DetailById(detail) > 0;
    }
}